package org.dromara.system.controller.miniyi;

import org.dromara.common.core.domain.R;
import org.dromara.common.core.enums.TabTypeMinYiEnum;
import org.dromara.common.core.utils.TimeUtil;
import org.dromara.system.domain.vo.SplasheDetailsVO;
import org.dromara.system.domain.vo.WorkOrderInfoVO;
import org.dromara.system.domain.vo.ZServiceSplashesVO;
import org.dromara.system.mapper.MapMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 邹城民意散点图
 */
@RestController
@RequestMapping({"/splashes"})
public class ZServiceSplashesController {
   @Autowired
   private MapMapper splashesMapper;

    /**
     * 散点图
     * @param timeCode 时间类型[1-当日,2-7天,3-30天,4-当前年份,5-全部,6-年月(6与开始时间，结束时间关联，其余1，2，3，4，5有参无影响)]
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param tabCode 模块名称 [1-高频热点,2-诉求类型,3-一级问题,4-二级问题,5-诉求渠道,6-三级问题]
     * @param chartName X轴参数
     * @return
     */
   @GetMapping({"map"})
   public R<List<ZServiceSplashesVO>> splashes(@RequestParam Integer timeCode,
                                               @RequestParam(defaultValue = "2022-01-01") String startTime,
                                               @RequestParam(defaultValue = "2022-01-15")  String endTime,
                                               @RequestParam Integer tabCode,
                                               @RequestParam String chartName) {
      String time = TimeUtil.buildTime(timeCode, startTime, endTime);
      List<ZServiceSplashesVO> Splashes = this.splashesMapper.getSplashes(chartName, time, TabTypeMinYiEnum.getTypeByCode(tabCode));
      return R.ok(Splashes);
   }

    /**
     * 散点详情及工单轨迹
     * @param id 散点ID
     * @return
     */
   @GetMapping({"details"})
   public R<SplasheDetailsVO> splasheDetails(@RequestParam Integer id) {
      SplasheDetailsVO SplasheDetails = this.splashesMapper.getSplasheDetailsById(id);
      List<WorkOrderInfoVO> workOrderInfo = this.splashesMapper.getWorkOrderInfo(id);
      if (workOrderInfo.size() != 0) {
         SplasheDetails.setList(workOrderInfo);
      }

      return R.ok(SplasheDetails);
   }
}
